package me.kagami.myplugin.form;

import com.intellij.ide.RecentProjectsManagerBase;
import com.intellij.ide.ReopenProjectAction;
import com.intellij.openapi.actionSystem.AnAction;
import me.kagami.myplugin.extensions.CustomizeSettingsState;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CustomizeSettingsComponent {
    private JTextField customizeViewPaneName;
    private JPanel mypanel;
    private JTextField quickStart1;
    private JTextField quickStart2;
    private JTextField quickStart3;
    private JTextField quickStart4;
    private JTextField quickStart5;
    private JTextField quickStart6;
    private JComboBox comboBox1;
    private JComboBox comboBox2;
    private JComboBox comboBox3;
    private JComboBox comboBox4;
    private JComboBox comboBox5;
    private JComboBox comboBox6;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField3;
    private JTextField textField4;
    private JTextField textField5;
    private JTextField textField6;

    public CustomizeSettingsComponent() {
        RecentProjectsManagerBase recentProjectsManagerBase = RecentProjectsManagerBase.getInstanceEx();
        AnAction[] recentProjectsActions = recentProjectsManagerBase.getRecentProjectsActions(false, false);
        if (recentProjectsActions != null) {
            CustomizeSettingsState customizeSettingsState = CustomizeSettingsState.getInstance();
            for (AnAction action : recentProjectsActions) {
                ReopenProjectAction recentProjectsAction = (ReopenProjectAction) action;
                comboBox1.addItem(recentProjectsAction.getProjectPath());
                comboBox2.addItem(recentProjectsAction.getProjectPath());
                comboBox3.addItem(recentProjectsAction.getProjectPath());
                comboBox4.addItem(recentProjectsAction.getProjectPath());
                comboBox5.addItem(recentProjectsAction.getProjectPath());
                comboBox6.addItem(recentProjectsAction.getProjectPath());

                if (customizeSettingsState.getQuickProject1() != null && customizeSettingsState.getQuickProject1().equals(recentProjectsAction.getProjectPath())) {
                    comboBox1.setSelectedItem(recentProjectsAction.getProjectPath());
                }
                if (customizeSettingsState.getQuickProject2() != null && customizeSettingsState.getQuickProject2().equals(recentProjectsAction.getProjectPath())) {
                    comboBox2.setSelectedItem(recentProjectsAction.getProjectPath());
                }
                if (customizeSettingsState.getQuickProject3() != null && customizeSettingsState.getQuickProject3().equals(recentProjectsAction.getProjectPath())) {
                    comboBox3.setSelectedItem(recentProjectsAction.getProjectPath());
                }
                if (customizeSettingsState.getQuickProject4() != null && customizeSettingsState.getQuickProject4().equals(recentProjectsAction.getProjectPath())) {
                    comboBox4.setSelectedItem(recentProjectsAction.getProjectPath());
                }
                if (customizeSettingsState.getQuickProject5() != null && customizeSettingsState.getQuickProject5().equals(recentProjectsAction.getProjectPath())) {
                    comboBox5.setSelectedItem(recentProjectsAction.getProjectPath());
                }
                if (customizeSettingsState.getQuickProject6() != null && customizeSettingsState.getQuickProject6().equals(recentProjectsAction.getProjectPath())) {
                    comboBox6.setSelectedItem(recentProjectsAction.getProjectPath());
                }

            }
        }
    }

    public JPanel getMypanel() {
        return mypanel;
    }

    public JTextField getCustomizeViewPaneName() {
        return customizeViewPaneName;
    }

    public JTextField getQuickStart1() {
        return quickStart1;
    }

    public JTextField getQuickStart2() {
        return quickStart2;
    }

    public JTextField getQuickStart3() {
        return quickStart3;
    }

    public JTextField getQuickStart4() {
        return quickStart4;
    }

    public JTextField getQuickStart5() {
        return quickStart5;
    }

    public JTextField getQuickStart6() {
        return quickStart6;
    }

    public String getQuickProject1() {
        Object selectedItem = comboBox1.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public String getQuickProject2() {
        Object selectedItem = comboBox2.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public String getQuickProject3() {
        Object selectedItem = comboBox3.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public String getQuickProject4() {
        Object selectedItem = comboBox4.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public String getQuickProject5() {
        Object selectedItem = comboBox5.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public String getQuickProject6() {
        Object selectedItem = comboBox6.getSelectedItem();
        if (selectedItem == null) {
            return "";
        } else {
            return selectedItem.toString();
        }
    }

    public void setQuickProject1(String path) {
        comboBox1.setSelectedItem(path);
    }

    public void setQuickProject2(String path) {
        comboBox2.setSelectedItem(path);
    }

    public void setQuickProject3(String path) {
        comboBox3.setSelectedItem(path);
    }

    public void setQuickProject4(String path) {
        comboBox4.setSelectedItem(path);
    }

    public void setQuickProject5(String path) {
        comboBox5.setSelectedItem(path);
    }

    public void setQuickProject6(String path) {
        comboBox6.setSelectedItem(path);
    }


    public void setQuickProjectSimpleName1(String path) {
        textField1.setText(path);
    }

    public void setQuickProjectSimpleName2(String path) {
        textField2.setText(path);
    }

    public void setQuickProjectSimpleName3(String path) {
        textField3.setText(path);
    }

    public void setQuickProjectSimpleName4(String path) {
        textField4.setText(path);
    }

    public void setQuickProjectSimpleName5(String path) {
        textField5.setText(path);
    }

    public void setQuickProjectSimpleName6(String path) {
        textField6.setText(path);
    }

    public String getQuickProjectSimpleName1() {
        if (textField1 == null) {
            return "";
        }
        return textField1.getText();
    }

    public String getQuickProjectSimpleName2() {
        if (textField2 == null) {
            return "";
        }
        return textField2.getText();
    }

    public String getQuickProjectSimpleName3() {
        if (textField3 == null) {
            return "";
        }
        return textField3.getText();
    }

    public String getQuickProjectSimpleName4() {
        if (textField4 == null) {
            return "";
        }
        return textField4.getText();
    }

    public String getQuickProjectSimpleName5() {
        if (textField5 == null) {
            return "";
        }
        return textField5.getText();
    }

    public String getQuickProjectSimpleName6() {
        if (textField6 == null) {
            return "";
        }
        return textField6.getText();
    }
}
